﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Guoc.BigMall.Infrastructure.Payment
{
    public class PayService : IPayService
    {
        static List<IPayGetway> _getwaylist = new List<IPayGetway>();

        public void AddGetway(IPayGetway getway)
        {
            _getwaylist.Add(getway);  
            
           
        }

        public T GetPayGetway<T>(string storeCode) where T : IPayGetway
        {
            var getway = _getwaylist.FirstOrDefault(n => n.StoreCode == storeCode && n.GetType() == typeof(T));
            if (getway == null) { throw new FriendlyException(string.Format("{0}支付网关不存在", storeCode)); }
            return (T)getway;
        }
    }
}
